﻿using System.IO;
using Comkarl.Restful.Shell.External;

namespace SampleCommands
{
    [ShellCommandName("write-file")]
    public sealed class WriteFileCommand : Comkarl.Restful.Shell.External.ShellCommand
    {
        /* You give a name to the argument and a default value in test environment. */
        [ShellCommandArgument("filename")]
        [ShellTestArgumentValue("file.txt")]
        public string FileName
        {
            get;
            set;
        }

        public override void Execute(ShellResponse response)
        {
            /* Note you need to resolve data path. That's because Restful Framework won't allow you to
             * write a file to any file system location, but to current application data path. */
            File.WriteAllText(ShellUtility.ResolveDataPath(AppKey, FileName), "Hello world in this file!");
        }
    }
}